
let ajax = 0

const request = ({ url, data, method }) => {
  ajax++
  wx.showLoading({
    title: '加载中',
  })
  
  let baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"
  return new Promise((resolve,reject) => {
    wx.request({
      url: baseUrl + url,
      data,
      method: method? 'GET': method,
      success: (res) => {
        resolve(res.data.message)
      },
      fail: (error) => {
        reject(error)
      },
      complete: () => {
        ajax--
        if (ajax === 0) {
          wx.hideLoading({
            success: (res) => {},
          })
        }
      }
    })
  })
}

export default request

// 调用
// let res = request({ url: "/goods/detail", data: this.data.data })